#include "StdAfx.h"
#include "factory.h"
#include "StartNode.h"
#include "EndNode.h"
#include "AND.h"
#include "NAND.h"
#include "OR.h"
#include "NOR.h"
#include "NOT.h"
#include "XOR.h"

void factory::assign( const char* szID, Node* pNode )
{
	NodeMap	&cMap = getMap();

	cMap[szID] = pNode;
}

Node* factory::create(string component)
{
	
	NodeMap	&cMap = getMap();
	NodeMap::iterator	iFind = cMap.find( component );

	if ( iFind == cMap.end() )
		return NULL;
	else
		return iFind->second->clone();
}

factory::NodeMap& factory::getMap()
{
	 static NodeMap cMap;
	 return cMap;
}

/*
	Node* comp = 0;
	if(component == "INPUT_HIGH")
	{
		comp = new StartNode(1);
	}
	else if(component == "INPUT_LOW")
	{
		comp = new StartNode(0);
	}
	else if(component == "PROBE")
	{
		comp = new EndNode();
	}
	else if(component == "AND")
	{
		comp = new AND();
	}
	else if(component == "NOT")
	{
		comp = new NOT();
	}
	else if(component == "NOR")
	{
		comp = new NOR();
	}
	else if(component == "NAND")
	{
		comp = new NAND();
	}
	else if(component == "XOR")
	{
		comp = new XOR();
	}
	else if(component == "OR")
	{
		comp = new OR();
	}
	return comp;
	*/